<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :formType="type" @formChange="formChangeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FormPanel ref="formPanel1" :list="formList1" :formType="type" @formChange="formChangeHandle1" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FilterTable ref="table" height="auto" :isSelectColumn="false" :columns="columns" :dataSource="tableList" :onColumnsChange="columns => (this.columns = columns)" />

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <multiuse-button type="primary" :click="dataHandle">下 发</multiuse-button>
      <el-button @click="closeDrawer">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import { getUser } from '@/assets/js/auth';
import { queryById, mailIssued } from '@/api/omFinance/InvoiceMailManage/MailSend';

export default {
  name: 'SonModel',
  mixins: [dictionary],

  props: ['type', 'rowData'],
  data() {
    this.BaseTable = null;
    this.saveData = null;
    this.saveData1 = null;

    return {
      formList: this.createdFrom(),
      formList1: this.createdFrom1(),
      columns: this.createdTable(),
      recipientId: '',
      sendId: '',
      ids: [],
      tableList: [],
      isCan: false
    };
  },
  created() {
    this.queryByIdFun();
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async queryByIdFun() {
      
      const res = await queryById(this.rowData.id);
      
      if (res.resultCode == 200) {
        let recipientDTO = res.data.recipientDTO;
        let sendDTO = res.data.sendDTO;
        // this.recipientId = recipientDTO.id;
        // this.sendId = sendDTO.id;
        this.tableList = res.data.registrationDTOS;
        
        this.formList.map(x => {
          if (x.fieldName == 'mailNo') {
            x.initialValue = res.data.mailNo;
          } else if (x.fieldName == 'dealerCode') {
            x.initialValue = res.data.dealerCode;
          } else if (x.fieldName == 'dealerName') {
            x.initialValue = res.data.dealerName;
          } else if (x.fieldName == 'djr' || x.fieldName == 'djrq') {
          } else if (x.fieldName == 'remark') {
            x.initialValue = res.data.remark;
          } else {
            x.initialValue = sendDTO[x.fieldName];
          }
        });
        this.formList1.map(x => {
          x.initialValue = recipientDTO[x.fieldName];
        });
      }
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    formChangeHandle1(val) {
      this.saveData1 = val;
    },
    // 登记   寄件人ID、收件人ID、动力形式、业务类型、经销商代码、经销商名称、备注、发票选中的ID；
    async dataHandle() {
      this.$refs.formPanel.SUBMIT_FORM();
      this.$refs.formPanel1.SUBMIT_FORM();
      if (this.saveData) {
        let res = await mailIssued([this.rowData.id]);

        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '操作成功' });
          this.$emit('close', false, 'refresh');
        }
      }
    },
    closeDrawer() {
      this.$emit('close', false);
    },

    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '邮寄单号',
          fieldName: 'mailNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '登记人',
          fieldName: 'djr',
          placeholder: '',
          initialValue: getUser(),
          disabled: true
        },
        {
          type: 'DATE',
          label: '登记日期',
          fieldName: 'djrq',
          initialValue: moment().format('YYYY-MM-DD'),
          dateType: 'exactdate',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          placeholder: '请输入',
          selfCols: 3
        },
        {
          type: 'BREAK_SPACE',
          label: '寄件人信息'
        },
        {
          type: 'INPUT',
          label: '姓名',
          fieldName: 'recipientName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'recipientPostCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电话',
          fieldName: 'recipientPhone',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '移动电话',
          fieldName: 'recipientMobile',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '所在省',
          fieldName: 'provinceName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '所在市',
          fieldName: 'cityName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '所在区（县）',
          fieldName: 'districtName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '详细地址',
          fieldName: 'address',
          selfCols: 2,
          placeholder: '',
          disabled: true
        }
      ];
    },
    createdFrom1() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '收件人信息'
        },
        {
          type: 'INPUT',
          label: '姓名',
          fieldName: 'recipientName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'recipientPostCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电话',
          fieldName: 'recipientPhone',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '移动电话',
          fieldName: 'recipientMobile',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '省份',
          fieldName: 'provinceName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '所在市',
          fieldName: 'cityName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '县区',
          fieldName: 'districtName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '详细地址',
          fieldName: 'address',
          selfCols: 2,
          placeholder: '',
          disabled: true
        },
        {
          type: 'BREAK_SPACE',
          label: '发票列表'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '发票号码',
          dataIndex: 'goldenInvoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '发票代码',
          dataIndex: 'goldenInvoiceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '业务类型',
          dataIndex: 'buzinessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6089'),
          render: props => {
            return <span>{this.createDictText(props.row.buzinessType, '6089')}</span>;
          }
        }
      ];
    }
  }
};
</script>
